package dart

class RoundTests extends DartTestCase {

	void testGetScoreCountingDown() {
		Game game = new Game(countDown: true, startingScore: 100,
				endingScore: 0, scoreLimit: null, bounceBack: null)
		Round round = addRound(addPlayerGame(game))

		assertEquals(100, round.getScore(game.startingScore))

		addSuccess(round, 5, 1)
		assertEquals(95, round.getScore(game.startingScore))

		addSuccess(round, 20, 1)
		assertEquals(75, round.getScore(game.startingScore))

		addPenalty(round, 10, 10)
		assertEquals(85, round.getScore(game.startingScore))
	}

	void testGetScoreCountingUp() {
		Game game = new Game(countDown: false, startingScore: 0,
				endingScore: 100, scoreLimit: null, bounceBack: null)
		Round round = addRound(addPlayerGame(game))
		
		assertEquals(0, round.getScore(game.startingScore))

		addSuccess(round, 5, 1)
		assertEquals(5, round.getScore(game.startingScore))

		addSuccess(round, 20, 1)
		assertEquals(25, round.getScore(game.startingScore))

		addPenalty(round, 10, 10)
		assertEquals(15, round.getScore(game.startingScore))
	}

	void testGetScoreGoingBeyondLimit() {
		Game game = new Game(countDown: true, startingScore: 100,
				endingScore: 0, scoreLimit: 103, bounceBack: null)
		Round round = addRound(addPlayerGame(game))
		addPenalty(round, 10, 10);
		assertEquals(103, round.getScore(game.startingScore))

		game.scoreLimit = null;
		assertEquals(110, round.getScore(game.startingScore))


		game = new Game(countDown: false, startingScore: 0,
				endingScore: 100, scoreLimit: -3, bounceBack: null)
		round = addRound(addPlayerGame(game))
		addPenalty(round, 10, 10);
		assertEquals(-3, round.getScore(game.startingScore))

		game.scoreLimit = null;
		assertEquals(-10, round.getScore(game.startingScore))
	}

	void testGetScoreBouncingBack() {
		Game game = new Game(countDown: true, startingScore: 10,
				endingScore: 5, scoreLimit: null, bounceBack: 3)
		Round round = addRound(addPlayerGame(game))
		addSuccess(round, 20, 1);
		assertEquals(16, round.getScore(game.startingScore))

		game = new Game(countDown: false, startingScore: 90,
				endingScore: 100, scoreLimit: -3, bounceBack: 102)
		round = addRound(addPlayerGame(game))
		addSuccess(round, 20, 1);
		assertEquals(94, round.getScore(game.startingScore))
	}

	void testBusting() {
		Game game = new Game(countDown: true, startingScore: 10,
				endingScore: 0, scoreLimit: null, bounceBack: null)
		Round round = addRound(addPlayerGame(game))
		addSuccess(round, 5, 1);
		addSuccess(round, 20, 1);
		assertEquals(5, round.getScore(game.startingScore))
		assertTrue(round.isBust(game.startingScore))

		game = new Game(countDown: false, startingScore: 90,
				endingScore: 100, scoreLimit: null, bounceBack: null)
		round = addRound(addPlayerGame(game))
		addSuccess(round, 5, 1);
		addSuccess(round, 20, 1);
		assertEquals(95, round.getScore(game.startingScore))
		assertTrue(round.isBust(game.startingScore))
	}

}